<?php
//PLUGIN type=frontend
//PLUGIN name=Sitemap
//PLUGIN desc=Generates XML sitemaps for the page. The sitemap is at /sitemap.xml
//PLUGIN group=general

global $options; // Use the options var

if($options['urlname'] == 'sitemap.xml' || $options['urlname'] == 'sitemap') {


    function createSitemap($in,$a = array()) {
        if(!empty($in['url'])) {
            $a[] = $in['url'];
        }
        if(is_array($in["children"])) {
            foreach($in["children"] as $c) {
                createSitemap($c,&$a);
            }
        }
        return $a;
    }


    header('Content-Type: application/xml; charset=UTF-8');
    print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    print "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"
            xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
            xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n";
    foreach(createSitemap(menu(_CONTENTPATH_)) as $x) {
        print "\t<url>\n";
        print "\t\t<loc>{$x}</loc>\n";
        print "\t</url>\n";
    }
    print '</urlset>';
    exit();
}
?>